/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package HouseBN;

import DataAccess.HouseDA;
import entity.House;
import entity.SwhUser;
import entity.SwhUser;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author Mr-Quick
 */
public class SellerBN {

    EntityManager em;

    public SellerBN() {
        String persistenceUnitName = "SweetHomePU";
        EntityManagerFactory factory = Persistence.createEntityManagerFactory(persistenceUnitName);
        em = factory.createEntityManager();
    }

    public void Addseller(House h, SwhUser u) {
//        Query add = em.createQuery("insert into House values (:Idhouse, :Iduser, :title, :Date, :Earth, :House, :city, :location, :bed, :bath, :living, :typehouse, :type, :deposit, : introduction, :payment)", HouseDA.class);
//        add.setParameter("Idhouse", h.getIdHouse());
//        add.setParameter("Iduser", u.getIDUser());
//        add.setParameter("title", h.getTittlehouse());
//        add.setParameter("Date", h.getDateUp());
//        add.setParameter("Earth", h.getSquarefootageEarth());
//        add.setParameter("House", h.getSquarefootageHouse());
//        add.setParameter("city", h.getCity());
//        add.setParameter("location", h.getLocation());
//        add.setParameter("bed", h.getBedroom());
//        add.setParameter("bath", h.getBathroom());
//        add.setParameter("living", h.getLivingroom());
//        add.setParameter("typehouse", h.getTypehouse());
//        add.setParameter("type", h.getType());
//        add.setParameter("deposit", h.getDeposit());
//        add.setParameter("introduction", h.getIntroduction());
//        add.setParameter("payment", h.getTypepayment());
        try {
            HouseDA hda = new HouseDA(em);
            em.getTransaction().begin();
            hda.create(h);
            em.getTransaction().commit();
        }catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
    
    
}
